package br.ufpe.cin.rgms.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.servlet.ServletContext;

public class Properties {
	
	private static java.util.Properties properties;
	
	public static String getProperty(ServletContext servletContext, String key){
		if(Properties.properties == null){
			String path = servletContext.getRealPath("/properties"); 
		//	File propertiesFolder = new File("WebContent/properties");
			File propertiesFolder = new File(path);
			
			File[] properties = propertiesFolder.listFiles();
			
			Properties.properties = new java.util.Properties();
			try {
				for(File property : properties)
				{
					if(property.getName().endsWith("properties"))
					{
						Properties.properties.load(new FileInputStream(property));
					}
				}
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return Properties.properties.getProperty(key);
	}

}
